package com.ruoyi.erp.domain;

import java.math.BigDecimal;
import java.util.Date;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.ruoyi.common.utils.StringUtils;
import lombok.Data;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import com.ruoyi.common.annotation.Excel;
import com.ruoyi.common.core.domain.BaseEntity;

/**
 * 收款计划对象 receivable_plan
 * 
 * @author sauger
 * @date 2022-03-28
 */
@Data
public class ReceivablePlan extends BaseEntity
{
    private static final long serialVersionUID = 1L;

    /**  */
    private Integer id;

    /** 客户 */
    @Excel(name = "客户")
    private String customerName;

    private Integer customerId;

    /** 项目 */
    @Excel(name = "项目")
    private String title;

    private String projectName;

    private String settleName;

    private Integer projectId;

    /** 计划类型 */
    private String planType;

    /** 事业部 */

    private String businessUnitName;

    private Integer businessUnitId;
    @Excel(name = "成本中心")
    private String businessUnitDepartmentName;

    private Integer businessUnitDepartmentId;

    /** 收款笔数 */
    @Excel(name = "收款笔数", dictType = "account_number")
    private String planNumber;

    /** 计划收款金额 */
    @Excel(name = "计划收款金额")
    private BigDecimal expectAmount;

    @Excel(name = "已收金额")
    private BigDecimal payedAmount;

    /** 计划收款时间 */
    @JsonFormat(pattern = "yyyy-MM-dd")
    @Excel(name = "计划收款时间", width = 30, dateFormat = "yyyy-MM-dd")
    private Date planReceiveDate;

    /** 上次收款时间 */
    @JsonFormat(pattern = "yyyy-MM-dd")
    @Excel(name = "上次收款时间", width = 30, dateFormat = "yyyy-MM-dd")
    private Date latestReceiveDate;

    /** 计划状态 */
    @Excel(name = "计划状态", dictType = "receivable_status_type")
    private String planStatus;

    /** 认证类型 */
    @Excel(name = "认证类型", dictType = "cognizance_type")
    private String cognizanceType;

    /** 认定时间 */
    @JsonFormat(pattern = "yyyy-MM-dd")
    @Excel(name = "认定时间", width = 30, dateFormat = "yyyy-MM-dd")
    private Date cognizanceDate;

    /** 已开发票 */
    @Excel(name = "已开发票", dictType = "sys_yes_no")
    private String invoiceStatus;

    /** 备注 */
    private String description;

    public String getTitle() {
        return StringUtils.isNull(this.projectName) ?  this.settleName : this.projectName;
    }

    public BigDecimal getPayedAmount()
    {
        return StringUtils.isNull(this.payedAmount)  ? BigDecimal.ZERO : this.payedAmount;
    }

    public String getPlanStatus()
    {
        if (StringUtils.isNull(this.payedAmount)) {
            return "expect";
        }
        return this.payedAmount.compareTo(this.expectAmount) == -1 ? "expect" : "received";
    }
}
